#ifndef COM_PORT_H
#define COM_PORT_H 1

#include <string.h>
#include <pthread.h>
#include <map>
#include "MessageQueue.h"

#define MAX_COM_PORT_COUNT 20
#define COM_PORT_BUF_SIZE 1000

class com_port
{
private:
	int com_port_fd_list[MAX_COM_PORT_COUNT];
	char buf[COM_PORT_BUF_SIZE];

	int max_com_port_fd;

	pthread_t thread_recv_msg;
	pthread_t thread_send_msg;
	MessageQueue *_message_queue;
	MessageQueue *_recv_message_queue;

	std::map<int, int> com_port2fd;
	std::map<int, int> fd2com_port;

	// const char * device_names[] = 
	// {
	// device_names_str.push_back("/dev/ttyS9");
	// device_names_str.push_back("/dev/ttyS3");
	// device_names_str.push_back("/dev/ttyS2");
	// device_names_str.push_back("/dev/ttyS8");
	// device_names_str.push_back("/dev/ttyS5");
	// device_names_str.push_back("/dev/ttyS6");
	// device_names_str.push_back("/dev/ttyS10");
	// device_names_str.push_back("/dev/ttyS7");
	// device_names_str.push_back("/dev/ttySAC0");
	// device_names_str.push_back("/dev/ttySAC1");
	// device_names_str.push_back("/dev/ttySAC2");
	// device_names_str.push_back("/dev/ttySAC3");
	// device_names_str.push_back("/dev/ttySAC4");
	// device_names_str.push_back("/dev/ttySAC5");
	// device_names_str.push_back("/dev/ttySAC6");
	// device_names_str.push_back("/dev/ttySAC7");
	// };

	void recv_buffer(int fd);

public:
	com_port();

	void recv_msg();
	void send_msg();

	bool start_recv_msg(MessageQueue * mq);
	bool stop_recv_msg();

	bool start_send_msg(MessageQueue * mq);
	bool stop_send_msg();
};

#endif